package com.example.yyg.springframework.core.io;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * @Author: 冰岩
 * @Date: 2023/07/02
 * @Description:
 */
public class DefaultResourceLoader implements ResourceLoader{
    @Override
    public Resource getResource(String path) {
        if (path.startsWith(CLASS_PATH_RESOURCE_PREFIX)) {
            return new ClassPathResource(path.substring(CLASS_PATH_RESOURCE_PREFIX.length()));
        } else {
            try {
                URL url = new URL(path);
                return new UrlResource(url);
            } catch (MalformedURLException e) {
                return new FileSystemResource(path);
            }
        }
    }
}
